import { customRef } from 'vue'

export default function (initialValue: string, delay: number) {
  let msg = customRef((track, trigger) => {
    let timer: number
    return {
      get() {
        track()
        return initialValue
      },
      set(value) {
        clearTimeout(timer)
        timer = setTimeout(() => {
          initialValue = value
          alert(`过了${delay / 1000}秒,已修改完毕`)
          trigger()
        }, delay)
      },
    }
  })
  return { msg }
}
